<template>
  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="活动名称" align="center" prop="name" />
      <el-table-column label="活动时间" align="center" prop="activeDate" width="200px">
        <template #default="scope">
          {{ scope.row.activeDate }} {{ scope.row.activeTimeBegin }}-{{ scope.row.activeTimeEnd }}
        </template>
      </el-table-column>
      <el-table-column label="男人数" align="center" prop="menNum" />
      <el-table-column label="女人数" align="center" prop="womenNum" />
      <el-table-column label="审核状态" prop="auditStatus" width="90">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.AUDIT_STATUS" :value="scope.row.auditStatus" />
        </template>
      </el-table-column>
      <el-table-column label="活动来源" align="center" prop="activeSource">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.ACTIVITYTYPE" :value="scope.row.activeSource" />
        </template>
      </el-table-column>
      <el-table-column
        label="报名时间"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column label="操作" align="center" fixed="right">
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="openDetail(scope.row.id)"
            v-if="scope.row.auditStatus !== 0"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

  <!-- 详情弹窗：查看 -->
  <Detail ref="formRefDetail" />
</template>

<script setup lang="ts">
import { DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import Detail from './Detail.vue'
import * as ActivityInfoApi from '@/api/blind/activityInfo'

defineOptions({ name: 'Activity' })
const { user } = withDefaults(defineProps<{ user?: any }>(), { user: null })

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  headUserId: null
})

/** 查询列表 */
const getList = async () => {
  queryParams.headUserId = user?.id
  loading.value = true
  try {
    const data = await ActivityInfoApi.getActivityInfoPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 打开详情 */
const formRefDetail = ref()
const openDetail = (id?: number) => {
  formRefDetail.value.open(id)
}
/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
